<html><body><pre>
<script>
Function.prototype.method = function (name, func) {
    this.prototype[name] = func;
    return this;
}
Array.method('each', 
    function(f) {
        for (var i=0; i<this.length; i++) {
            f(this[i]);
        }
    }
);
var v = [10, 20, 30];
// should work, but doesn't:
// v.each(document.writeln);
/* Error: uncaught exception: 
  [Exception... "Illegal operation on WrappedNative prototype object"  
  nsresult: "0x8057000c (NS_ERROR_XPC_BAD_OP_ON_WN_PROTO)"  
  location: "JS frame :: 
  file:///home/luciano/prj/ramgarlic/gcode/js/each.html :: 
  anonymous :: line 10"  data: no] */

// this works
v.each(function (x) {document.writeln(x)});


</script>
</pre></body></html>
